package com.zoe.wan.android.example.activity.webview

import android.webkit.WebSettings
import com.zoe.wan.android.example.R
import com.zoe.wan.base.BaseActivity
import com.zoe.wan.android.example.BR
import com.zoe.wan.android.example.databinding.ActivityWebviewBinding

class WebActivity: BaseActivity<ActivityWebviewBinding,WebViewModel>() {

    companion object{
        const val INTENT_WEB_TITLE_KEY = "INTENT_WEB_TITLE_KEY"
        const val INTENT_WEB_URL_KEY = "INTENT_WEB_URL_KEY"

    }
    override fun getLayoutId(): Int {
        return R.layout.activity_webview
    }

    override fun getViewModelId(): Int {
         return BR.webVm
    }

    override fun initViewData() {
        binding?.back?.setOnClickListener {
            finish()
        }
        val title =  intent.getStringExtra(INTENT_WEB_TITLE_KEY)
        val link =  intent.getStringExtra(INTENT_WEB_URL_KEY)
        if (title != null) {
            viewModel?.webTitle = title
        }
        binding?.webView?.loadUrl(link ?: "")

        initWebViewSetting()
    }

  private fun initWebViewSetting(){
      binding?.webView?.settings?.apply {
          // 设置支持js脚本
          this.javaScriptEnabled = true
          // 自适应
          this.useWideViewPort = true
          this.loadWithOverviewMode = true

          this.setSupportZoom(true)

          // 关闭缓存
          this.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK
          // 打开新的文件
          this.allowContentAccess = true

          // 支持js打卡新的界面
          this.javaScriptCanOpenWindowsAutomatically = true

          // 自动加载图片
          this.loadsImagesAutomatically = true

//            this.setde
      }

//      binding?.webView?.webViewClient
  }


}